package com.nf.health.app.activity.miansearch.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.nf.health.app.R;
import com.nf.health.app.customview.CircleImageView;
import com.nf.health.app.inquiry.docdetail.DocDetailActivity;
import com.nf.health.app.models.SearchMainDocBean;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.widget.OnMyOnClistener;

import java.util.List;

/**
 * Created by Jason on 2016/9/28.
 */
public class ListMainSearchAdapter extends BaseAdapter{
    private int CPOUNT_ITEM_NUM = 0;
    private LayoutInflater inflater;
    private Activity cnt ;
    private OnMyOnClistener onMyOnClistener;//注册点击事件

    public List<SearchMainDocBean> listSearchMainBean;


    public ListMainSearchAdapter(Activity cnt, List<SearchMainDocBean> listSearchMainBean){
        inflater =LayoutInflater.from(cnt);
        this.cnt = cnt;
        this.listSearchMainBean = listSearchMainBean;
    }
    public void setDoctorCommentData(List<SearchMainDocBean> datas){
        this.listSearchMainBean = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return listSearchMainBean.size();
    }

    @Override
    public Object getItem(int position) {
        return listSearchMainBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null) {
            convertView = View.inflate(cnt, R.layout.view_searchmain_doc2, null);
            holder = new ViewHolder();
            holder.iv_personal_doc_item_serch = (CircleImageView) convertView.findViewById(R.id.iv_personal_doc_item_serch);
            holder.tv_item_doc_name_serch = (TextView) convertView.findViewById(R.id.tv_item_doc_name_serch);
            holder.tv_item_doc_address_serch = (TextView) convertView.findViewById(R.id.tv_item_doc_address_serch);
            holder.tv_assocital_num_serch = (TextView) convertView.findViewById(R.id.tv_assocital_num_serch);
            holder.tv_item_doc_type_serch = (TextView) convertView.findViewById(R.id.tv_item_doc_type_serch);
            holder.tv_item_doc_goodat_serch = (TextView) convertView.findViewById(R.id.tv_item_doc_goodat_serch);
            holder.rl_marchen  = (RelativeLayout) convertView.findViewById(R.id.rl_marchen);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
         final SearchMainDocBean searchMainDocBean = listSearchMainBean.get(position);
        if(searchMainDocBean == null){
            return convertView;
        }
        Glide.with(cnt)
                .load(searchMainDocBean.getHimg())
                .placeholder(R.drawable.default_head)
                .into(holder.iv_personal_doc_item_serch);
        holder.tv_assocital_num_serch.setVisibility(View.GONE);
        holder.tv_assocital_num_serch.setText(TextUtils.isEmpty(searchMainDocBean.getSignNumber()) ? "已签约0人" : "已签约" + searchMainDocBean.getSignNumber() + "人");
        holder.tv_item_doc_name_serch.setText(TextUtils.isEmpty(searchMainDocBean.getNick()) ? "未填写" : searchMainDocBean.getNick());
        holder.tv_item_doc_address_serch.setText(TextUtils.isEmpty(searchMainDocBean.getHospitalname()) ? "未填写" : searchMainDocBean.getHospitalname());
        holder.tv_item_doc_type_serch.setText(searchMainDocBean.getDepartment() + " | " + searchMainDocBean.getProfessional());
        holder.tv_item_doc_goodat_serch.setText(searchMainDocBean.getGoodremedy());
        holder.rl_marchen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle docDetailBundle = new Bundle();
                docDetailBundle.putString(DocDetailActivity.DOCTORID, searchMainDocBean.getDoctorid());
                ActivityUtils.showActivity(cnt, DocDetailActivity.class, docDetailBundle);
            }
        });
        return convertView;
    }

    static class ViewHolder{
       // @Bind(R.id.iv_personal_doc_item_serch)
        public CircleImageView iv_personal_doc_item_serch;

       /// @Bind(R.id.tv_item_doc_name_serch)//医生姓名
        public TextView tv_item_doc_name_serch;

        //@Bind(R.id.tv_item_doc_address_serch)
        TextView tv_item_doc_address_serch;//医院名称

       // @Bind(R.id.tv_assocital_num_serch)
        TextView tv_assocital_num_serch;//已签约225人"

        //@Bind(R.id.tv_item_doc_type_serch)
        TextView tv_item_doc_type_serch;//医生类别

        //@Bind(R.id.rl_marchen)
        RelativeLayout rl_marchen;//点击事件
        TextView tv_item_doc_goodat_serch;//点击事件

    }
}
